﻿using System;
using System.Windows;
using Baosight.ZNH.ZMCommon;
using Baosight.Platform.Core.UI.Controls;
using Baosight.Platform.Core;
using Baosight.ZNH.ZMCommon.ChildWindows;

namespace Baosight.ZNH.ZMCM.UI.ChildWindows
{
    /// <summary>
    /// Created by 李红星 2011-6-21
    /// 新增/修改材料费用额度管理
    /// </summary>
    public partial class MaterialRation : EFViewCmes
    {
        public MaterialRation(String dialogType)
        {
            InitializeComponent();
            base.BeforeAction += OnBeforeAction;
            Init(dialogType);
        }

        /// <summary>
        /// 初始化父类EFViewCmesProperty的值，每次点击“确定”、“返回”时执行此方法，从新赋值
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnBeforeAction(object sender, EventArgs e)
        {
            EFViewCmesProperty _view = new EFViewCmesProperty();
            _view.DataFields = this.InsertPanel.GetChildObjects<EFDataField>(null, true);
            base.ViewProperty = _view;
        }

        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="type"></param>
        private void Init(string type)
        {
            type = type == null ? "insert" : type.ToLower();

            switch (type)
            {
                case "insert":
                    this.deptName.IsReadOnly = true;
                    base.Mode = OperationMode.Insert;
                    break;
                case "update":
                    this.deptName.IsReadOnly = true;
                    this.fdYear.IsReadOnly = true;
                    this.fdMonth.IsEnabled = false;
                    base.Mode = OperationMode.Update;
                    break;
                default:
                    break;
            }
        }

        //public override bool ThisValidateField()
        //{
        //    Prompts pop = Prompts.getInstance();

        //    if (1 == 1)
        //    {
        //        pop.SetMsg("输入不合法, 请检查输入的数据！");
        //        pop.Show(6);
        //        return false;
        //    }

        //}

        /// <summary>
        /// 确定按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CommitClick(object sender, RoutedEventArgs e)
        {
            base.OnCommitButtonClick("ZMCM41", sender, e); 
        }

        /// <summary>
        /// 取消按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CancelClick(object sender, RoutedEventArgs e)
        {
            CmesWindows _window = this.Parent as CmesWindows;
            _window.DialogResult = false;
            _window.Close();
        }
    }
}